import time

import pyautogui
import pyperclip


class CommentReply(object):
    def __init__(self, comment_div):
        self.comment_div = comment_div

    def reply(self, comment_text):
        all_windows = pyautogui.getAllWindows()
        for window in all_windows:
            if "抖音搜索" in window.title:
                window.activate()
                pyautogui.leftClick(1491, 1012)  # 鼠标点击
                # 进行元素定位
                comment_element = self.comment_div.ele(f'tag:div@@text()={comment_text}')
                comment_element.parent(1).ele('tag:div@@tabindex=0@@text()=回复').click()
                pyperclip.copy("专业解决非标贷款，欢迎咨询！")  # 复制文本
                time.sleep(1)
                pyautogui.hotkey('ctrl', 'v')  # 粘贴文本
                pyautogui.leftClick(1491, 1012)  # 鼠标点击
                time.sleep(1)
                pyautogui.press('enter')  # 敲(按下并释放)回车键
